package com.zyz.B_流程控制.综合练习;

import java.util.Random;
import java.util.Scanner;

/**
 * @author: vick
 * @Date: 2025/3/11
 * @Description:
 * @version: 1.0
 */
public class Demo1 {
    public static void main(String[] args) {
        Random random = new Random();
        //生成随机数
        int number = random.nextInt(100) + 1;
        //用户猜的数字
        int userGuess = -1;
        //用户猜测的次数
        int count = 0;
        Scanner scanner = new Scanner(System.in);
        System.out.println("欢迎来到猜数字游戏，请输入1-100之间的数");

        while (userGuess != number){
            userGuess = scanner.nextInt();
            count++;

            if (userGuess < number) {
                System.out.println("太小了");
            } else if (userGuess > number) {
                System.out.println("太大了");
            }else {
                System.out.println("猜对了，一共猜了" + count + "次");
            }
        }
    }
}
